package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.mapper.TeachplanMediaMapper;
import com.xuecheng.content.service.TeachplanMediaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dongliang
 */
@Slf4j
@Service
public class TeachplanMediaServiceImpl extends ServiceImpl<TeachplanMediaMapper, TeachplanMedia> implements TeachplanMediaService {


    //根据mediaid判断媒资信息是否有绑定课程计划数据
    public Boolean RemoveTeachplanMedia(Long mediaId) {

        LambdaUpdateWrapper<TeachplanMedia> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(TeachplanMedia::getMediaId,mediaId);

        TeachplanMedia teachplanMedia = this.getOne(wrapper);

        if (ObjectUtils.isEmpty(teachplanMedia)){
            //不存在
            return false;
        }
        // TODO: 2021/12/17
        this.baseMapper.deleteById(teachplanMedia.getId());
        return true;
    }
}
